import { axios } from '@/utils/request'

const api = {
  commodity: '/commodities',
  commodityCategory: '/commodities/categories',
  commodityLabel: '/commodities/labels',
  commodityActivityLiveToday: '/commodities/live-today',
  commodityActivityPraiseReturn: '/commodities/praise-return'
}

export function getCommodityList (params) {
  return axios({
    url: api.commodity,
    method: 'get',
    params
  })
}

export function getCommodityInfo (id) {
  return axios({
    url: `${api.commodity}/${id}`,
    method: 'get'
  })
}

export function deleteCommodity (id) {
  return axios({
    url: `${api.commodity}/${id}`,
    method: 'delete'
  })
}

export function saveCommodity (data) {
  return axios({
    url: api.commodity + (data.hasOwnProperty('id') ? '/' + data.id : ''),
    method: data.hasOwnProperty('id') ? 'patch' : 'post',
    data
  })
}

export function getCommodityCategoryList (params) {
  return axios({
    url: api.commodityCategory,
    method: 'get',
    params
  })
}

export function deleteCommodityCategory (id) {
  return axios({
    url: `${api.commodityCategory}/${id}`,
    method: 'delete'
  })
}

export function saveCommodityCategory (data) {
  return axios({
    url: api.commodityCategory + (data.hasOwnProperty('id') ? '/' + data.id : ''),
    method: data.hasOwnProperty('id') ? 'patch' : 'post',
    data
  })
}

export function getCommodityLabelList (params) {
  return axios({
    url: api.commodityLabel,
    method: 'get',
    params
  })
}

export function deleteCommodityLabel (id) {
  return axios({
    url: `${api.commodityLabel}/${id}`,
    method: 'delete'
  })
}

export function saveCommodityLabel (data) {
  return axios({
    url: api.commodityLabel + (data.hasOwnProperty('id') ? '/' + data.id : ''),
    method: data.hasOwnProperty('id') ? 'patch' : 'post',
    data
  })
}

export function getCommodityActivityLiveTodayList (params) {
  return axios({
    url: api.commodityActivityLiveToday,
    method: 'get',
    responseType: params.hasOwnProperty('export') && !params.hasOwnProperty('async') ? 'blob' : 'json', // 导出 下载
    params
  })
}

export function liveTodayStockingExport (id) {
  return axios({
    url: `${api.commodityActivityLiveToday}/${id}/stocking-export`,
    method: 'get',
    responseType: 'blob'
  })
}

export function liveTodayInvoiceExport (id) {
  return axios({
    url: `${api.commodityActivityLiveToday}/${id}/invoice-export`,
    method: 'get',
    responseType: 'blob'
  })
}

export function saveCommodityActivity (data) {
  return axios({
    url: api.commodityActivityLiveToday + (data.hasOwnProperty('id') ? '/' + data.id : ''),
    method: data.hasOwnProperty('id') ? 'patch' : 'post',
    data
  })
}

export function getCommodityActivity (id) {
  return axios({
    url: `${api.commodityActivityLiveToday}/${id}`,
    method: 'get'
  })
}

export function getCommodityActivityLiveTodayInfo (id) {
  return axios({
    url: `${api.commodityActivityLiveToday}/${id}`,
    method: 'get'
  })
}

export function deleteCommodityActivityLiveToday (id) {
  return axios({
    url: `${api.commodityActivityLiveToday}/${id}`,
    method: 'delete'
  })
}

export function saveCommodityActivityLiveToday (data) {
  return axios({
    url: api.commodityActivityLiveToday + (data.hasOwnProperty('id') ? '/' + data.id : ''),
    method: data.hasOwnProperty('id') ? 'patch' : 'post',
    data
  })
}

export function commodityActivityLiveTodayUpperAndLowerShelves (id, status) {
  return axios({
    url: `${api.commodityActivityLiveToday}/${id}/status`,
    method: 'patch',
    data: {
      status
    }
  })
}

export function commodityActivityLiveTodayUpdateLocking (id, locking) {
  return axios({
    url: `${api.commodityActivityLiveToday}/${id}/locking`,
    method: 'patch',
    data: {
      locking
    }
  })
}

export function saveCommodityActivityLiveTodayMaterialSettings (id, data) {
  return axios({
    url: `${api.commodityActivityLiveToday}/${id}/material-settings`,
    method: 'patch',
    data
  })
}

export function saveCommodityActivityLiveTodayMomentsMaterialSettings (id, data) {
  return axios({
    url: `${api.commodityActivityLiveToday}/${id}/moments-settings`,
    method: 'patch',
    data
  })
}

export function getCommodityActivityPraiseReturnList (params) {
  return axios({
    url: api.commodityActivityPraiseReturn,
    method: 'get',
    responseType: params.hasOwnProperty('export') && !params.hasOwnProperty('async') ? 'blob' : 'json', // 导出 下载
    params
  })
}

export function praiseReturnStockingExport (id) {
  return axios({
    url: `${api.commodityActivityPraiseReturn}/${id}/stocking-export`,
    method: 'get',
    responseType: 'blob'
  })
}

export function praiseReturnInvoiceExport (id) {
  return axios({
    url: `${api.commodityActivityPraiseReturn}/${id}/invoice-export`,
    method: 'get',
    responseType: 'blob'
  })
}

export function getCommodityActivityPraiseReturnInfo (id) {
  return axios({
    url: `${api.commodityActivityPraiseReturn}/${id}`,
    method: 'get'
  })
}

export function deleteCommodityActivityPraiseReturn (id) {
  return axios({
    url: `${api.commodityActivityPraiseReturn}/${id}`,
    method: 'delete'
  })
}

export function saveCommodityActivityPraiseReturn (data) {
  return axios({
    url: api.commodityActivityPraiseReturn + (data.hasOwnProperty('id') ? '/' + data.id : ''),
    method: data.hasOwnProperty('id') ? 'patch' : 'post',
    data
  })
}

export function commodityActivityPraiseReturnUpperAndLowerShelves (id, status) {
  return axios({
    url: `${api.commodityActivityPraiseReturn}/${id}/status`,
    method: 'patch',
    data: {
      status: status
    }
  })
}

export function commodityActivityPraiseReturnUpdateLocking (id, locking) {
  return axios({
    url: `${api.commodityActivityPraiseReturn}/${id}/locking`,
    method: 'patch',
    data: {
      locking
    }
  })
}

export function saveCommodityActivityPraiseReturnMaterialSettings (id, data) {
  return axios({
    url: `${api.commodityActivityPraiseReturn}/${id}/material-settings`,
    method: 'patch',
    data
  })
}

export function saveCommodityActivityPraiseReturnMomentsMaterialSettings (id, data) {
  return axios({
    url: `${api.commodityActivityPraiseReturn}/${id}/moments-settings`,
    method: 'patch',
    data
  })
}

export function updateLiveTodaySku (id, data) {
  return axios({
    url: `${api.commodityActivityLiveToday}/sku/${id}`,
    method: 'patch',
    data
  })
}

export function updatePraiseReturnSku (id, data) {
  return axios({
    url: `${api.commodityActivityPraiseReturn}/sku/${id}`,
    method: 'patch',
    data
  })
}
